package com.dingding.order.core.pay.dao.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.dingding.common.core.base.dao.impl.BaseDaoImpl;
import com.dingding.common.core.base.daox.IBaseDaoX;
import com.dingding.common.core.beans.Userordert;
import com.dingding.common.core.beans.special.Specialuserlogin;
import com.dingding.order.core.pay.dao.IOrderPayDao;
import com.dingding.order.core.pay.dao.sql.OrderPaySQL;
import com.dingding.order.dto.grab.PushCompetitiveOrder;
import com.dingding.order.dto.pay.PassengerPayPushDTO;

/**
 * @Description: 支付订单DAO
 * @author fengshuonan
 * @date 2016年6月3日 下午5:53:07
 */
@Component("orderPayDao")
public class OrderPayDaoImpl extends BaseDaoImpl<Userordert> implements IOrderPayDao {

	@Resource(name = "baseDaoX")
	IBaseDaoX baseDaoX;
	
	/**
	 * @Description: 获取支付推送信息
	 * @param passengerId
	 *            乘客id
	 * @param driverId
	 *            车主id
	 * @author fengshuonan
	 * @return PassengerPayPushDTO
	 */
	@Override
	public PassengerPayPushDTO getPayPushInfo(String passengerId, String driverId) {

		// 创建乘客支付成功，给司机推送Bean
		PassengerPayPushDTO payPushDto = new PassengerPayPushDTO();

		// 根据司机Id,获取司机信息
		Object[] obj = null;
		try {
			obj = super.sqlQueryUnResultObj(OrderPaySQL.GET_PAY_PUSH, passengerId, driverId);
		} catch (Exception e) {
			log.info("乘客支付获取推送内容时出现异常  类：" + this.getClass() + " getPassengerPayPushInfo()", e);
		}

		// 判断司机信息是否为空
		if (obj != null && obj.length > 0) {

			// 将司机信息赋值给pushPassengerPay
			this.getPushPassengerPay(obj, payPushDto);
		}

		return payPushDto;
	}

	/**
	 * @Title: getPassengerPay @Description:
	 *         将Object[]类型转为PushPassengerPay @param obj 司机信息 @param
	 *         pushPassengerPay 推送对象 @return PushPassengerPay 返回类型 @throws
	 */
	private void getPushPassengerPay(Object[] obj, PassengerPayPushDTO pushPassengerPay) {

		// 司机Id(推送Id)
		if (obj[0] != null) {
			pushPassengerPay.setDriverId(obj[0].toString());
		}
		// 设备类型
		if (obj[1] != null) {
			// 设备类型 1:iOS 2:Android
			String deviceType = obj[1].toString();

			if (deviceType.equals("1")) { // 设备类型为：iOS
				pushPassengerPay.setLoginEquipment("iOS");
			} else if (deviceType.equals("2")) { // 设备类型为：Android
				pushPassengerPay.setLoginEquipment("Android");
			}

		}
		// 司机电话
		if (obj[2] != null) {
			pushPassengerPay.setTellPhone(obj[2].toString());
		}
		// 乘客姓名
		if (obj[3] != null) {
			pushPassengerPay.setPassengerName(obj[3].toString());
		}
		// 车牌号
		if (obj[4] != null) {
			pushPassengerPay.setLisencePlate(obj[4].toString());
		}
		// 司机名称
		if (obj[5] != null) {
			pushPassengerPay.setDriverName(obj[5].toString());
		}
	}

	/**
	 * @Description:乘客扣款
	 * @author fengshuonan
	 * @return PushCompetitiveOrder
	 */
	@Override
	public PushCompetitiveOrder passengerDebit(Userordert userordert, PushCompetitiveOrder pushCompetitiveOrder) {

		return null;

	}

	@Override
	public String getDriversAliasId(String driverId) {
		try {
			Specialuserlogin sul = this.baseDaoX.getById(driverId, Specialuserlogin.class);
			return sul.getAliasId();
		} catch (Exception e) {
			log.error("获取司机的aliasid错误！",e);
			return null;
		}
	}
	
	@Override
	public Specialuserlogin getSpecialUserLogin(String driverId){
		try {
			Specialuserlogin sul = this.baseDaoX.getById(driverId, Specialuserlogin.class);
			return sul;
		} catch (Exception e) {
			log.error("获取司机的aliasid错误！",e);
			return null;
		}
	}

}
